var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2DataManager = require("DataManager");
var $2FlbMathUtil = require("FlbMathUtil");
var $2UserDataManager = require("UserDataManager");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_BgCtrl = /* */function (_cc$Component5) {
  babel_inherits(c, _cc$Component5);
  var _super5 = babel_createSuper(c);
  function c() {
    var _this11;
    babel_classCallCheck(this, c);
    _this11 = _super5.apply(this, arguments);
    _this11.speed = 5;
    _this11.dir = -1;
    _this11.fdArr = [];
    _this11.zombieNode = null;
    return _this11;
  }
  babel_createClass(c, [{
    key: "onLoad",
    value: function onLoad() {
      this.init();
    }
  }, {
    key: "init",
    value: function init() {
      var _this12 = this;
      var e = this.node.children.length;
      var _loop = function _loop(_t) {
        _this12.node.children[_t].x = -_t * _this12.node.children[_t].width * _this12.dir;
        var e = cc.instantiate(_this12.fdArr[_t]);
        e.parent = _this12.node.children[_t].getChildByName("fds");
        e.active = true;
        e.setPosition(0, -100);
        var a = $2UserDataManager.default.instance.bwzjsInfo[$2DataManager.default.instance.fd_num].num;
        var n = $2UserDataManager.default.instance.bwzjsInfo[$2DataManager.default.instance.fd_num].gap;
        var _loop2 = function _loop2(_i3) {
          _this12.scheduleOnce(function () {
            var e = cc.instantiate(_this12.zombieNode);
            e.active = true;
            e.parent = _this12.node.children[_t].getChildByName("jss");
            var a = cc.winSize.width / 2 - 100 * (_i3 + 1);
            e.setPosition(a, -120);
          }, _i3 * n);
        };
        for (var _i3 = 0; _i3 < a; _i3++) {
          _loop2(_i3);
        }
        $2DataManager.default.instance.fd_num++;
      };
      for (var _t = 0; _t < e; _t++) {
        _loop(_t);
      }
    }
  }, {
    key: "set_dir",
    value: function set_dir(e) {
      this.dir = e;
    }
  }, {
    key: "setZindex",
    value: function setZindex() {
      var e = this.node.children.length;
      for (var _t2 = 0; _t2 < e; _t2++) {
        this.node.children[_t2].zIndex = 1;
      }
    }
  }, {
    key: "bgMove",
    value: function bgMove() {
      var e = this.node.children.length;
      $2DataManager.default.instance.distance += -this.speed * this.dir / this.speed / 20;
      if ($2DataManager.default.instance.distance < 0) {
        $2DataManager.default.instance.distance = 0;
      } else {
        for (var _t3 = 0; _t3 < e; _t3++) {
          this.node.children[_t3].x += this.speed * this.dir;
          if (this.dir > 0) {
            if (this.node.children[_t3].x >= this.node.children[_t3].width * this.dir) {
              $2DataManager.default.instance.fd_num--;
              this.node.children[_t3].x = -(e - 1) * this.node.children[_t3].width * this.dir;
              this.node.children[_t3].getChildByName("fds").removeAllChildren();
              this.node.children[_t3].getChildByName("jss").removeAllChildren();
              var _a = $2FlbMathUtil.MathUtil.getRandomInt(1, 2);
              var _n = cc.instantiate(this.fdArr[_a]);
              _n.active = true;
              _n.parent = this.node.children[_t3].getChildByName("fds");
              return void _n.setPosition(0, -100);
            }
          } else if (this.node.children[_t3].x <= this.node.children[_t3].width * this.dir) {
            $2DataManager.default.instance.fd_num++;
            this.node.children[_t3].x = -(e - 1) * this.node.children[_t3].width * this.dir;
            this.setZindex();
            this.node.children[_t3].zIndex = 99;
            this.node.children[_t3].getChildByName("fds").removeAllChildren();
            this.node.children[_t3].getChildByName("jss").removeAllChildren();
            var _a2 = $2FlbMathUtil.MathUtil.getRandomInt(1, 2);
            var _n2 = cc.instantiate(this.fdArr[_a2]);
            _n2.parent = this.node.children[_t3].getChildByName("fds");
            _n2.active = true;
            _n2.setPosition(0, -100);
            var _l = $2UserDataManager.default.instance.bwzjsInfo[$2DataManager.default.instance.fd_num].num;
            $2UserDataManager.default.instance.bwzjsInfo[$2DataManager.default.instance.fd_num].gap;
            for (var _e = 0; _e < _l; _e++) {
              var _a3 = cc.instantiate(this.zombieNode);
              _a3.parent = this.node.children[_t3].getChildByName("jss");
              var _n3 = cc.winSize.width / 2 - 100 * _e;
              _a3.setPosition(_n3, -100);
              _a3.active = true;
            }
          }
        }
      }
    }
  }, {
    key: "update",
    value: function update(e) {
      $2DataManager.default.instance.is_over || $2DataManager.default.instance.is_running && this.bgMove();
    }
  }]);
  return c;
}(cc.Component);
cc__decorate([ccp_property({
  type: [cc.Node]
})], def_BgCtrl.prototype, "fdArr", undefined);
cc__decorate([ccp_property(cc.Node)], def_BgCtrl.prototype, "zombieNode", undefined);
def_BgCtrl = cc__decorate([ccp_ccclass], def_BgCtrl);
exports.default = def_BgCtrl;